﻿using Basic.FlowModel.DB;
using Basic.FlowModel.NodeRoute;
using Basic.FlowRemoteModel.NodeRoute.Model;
using SqlSugar;
using WeDonekRpc.Helper.IdGenerator;
using WeDonekRpc.SqlSugar;

namespace Basic.FlowDAL.lmpl
{
    internal class FlowNodeRouteDAL : BasicDAL<DBFlowNodeRoute, long>, IFlowNodeRouteDAL
    {
        public FlowNodeRouteDAL ( IRepository<DBFlowNodeRoute> basicDAL ) : base(basicDAL, "node.route")
        {
        }
        public FromToNode[] GetsFromToNode ( long nodeId )
        {
            ISugarQueryable<FromToNode>[] tables = new ISugarQueryable<FromToNode>[]
            {
                this._BasicDAL.Queryable.Where(a=>a.ToNodeId==nodeId).Select(c=>new FromToNode
                {
                    NodeId=c.NodeId,
                    ToNodeId=c.ToNodeId
                }),
                 this._BasicDAL.Queryable.Where(a=>a.NodeId==nodeId).Select(c=>new FromToNode
                {
                    NodeId=c.NodeId,
                    ToNodeId=c.ToNodeId
                })
            };
            return this._BasicDAL.Gets(tables);
        }
        public long Add ( RouteAdd data )
        {
            DBFlowNodeRoute add = new DBFlowNodeRoute
            {
                Id = IdentityHelper.CreateId(),
                FlowId = data.FlowId,
                NodeId = data.NodeId,
                ToNodeId = data.ToNodeId
            };
            this._BasicDAL.Insert(add);
            return add.Id;
        }
    }
}
